package net.gq.logistics.mapper;

import java.util.List;
import net.gq.logistics.pojo.Customer;
import net.gq.logistics.pojo.CustomerExample;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;
import org.mybatis.caches.redis.RedisCache;
import org.springframework.stereotype.Component;

@Component("customerMapper")
@CacheNamespace(implementation = RedisCache.class)
public interface CustomerMapper {

    @Delete({
            "delete from t_customer",
            "where customer_id = #{customerId,jdbcType=BIGINT}"
    })
    int deleteByPrimaryKey(Long customerId);


    @Insert({
        "insert into t_customer (customer_id, customer_name, ",
        "phone, email, address, ",
        "gender, remark, ",
        "id_card, user_id, base_id)",
        "values (#{customerId,jdbcType=BIGINT}, #{customerName,jdbcType=VARCHAR}, ",
        "#{phone,jdbcType=VARCHAR}, #{email,jdbcType=VARCHAR}, #{address,jdbcType=VARCHAR}, ",
        "#{gender,jdbcType=INTEGER}, #{remark,jdbcType=VARCHAR}, ",
        "#{idCard,jdbcType=VARCHAR}, #{userId,jdbcType=BIGINT}, #{baseId,jdbcType=BIGINT})"
    })
    int insert(Customer record);

    @InsertProvider(type=CustomerSqlProvider.class, method="insertSelective")
    int insertSelective(Customer record);

    @SelectProvider(type=CustomerSqlProvider.class, method="selectByExample")
    @Results({
        @Result(column="customer_id", property="customerId", jdbcType=JdbcType.BIGINT),
        @Result(column="customer_name", property="customerName", jdbcType=JdbcType.VARCHAR),
        @Result(column="phone", property="phone", jdbcType=JdbcType.VARCHAR),
        @Result(column="email", property="email", jdbcType=JdbcType.VARCHAR),
        @Result(column="address", property="address", jdbcType=JdbcType.VARCHAR),
        @Result(column="gender", property="gender", jdbcType=JdbcType.INTEGER),
        @Result(column="remark", property="remark", jdbcType=JdbcType.VARCHAR),
        @Result(column="id_card", property="idCard", jdbcType=JdbcType.VARCHAR),
        @Result(column="user_id", property="userId", jdbcType=JdbcType.BIGINT),
        @Result(column="base_id", property="baseId", jdbcType=JdbcType.BIGINT),
        @Result(column="realname", property="realname", jdbcType=JdbcType.VARCHAR),
        @Result(column="section", property="section", jdbcType=JdbcType.VARCHAR)
    })
    List<Customer> selectByExample(CustomerExample example);

    

    @Select("select * from v_customer where customer_id =#{id}")
    @Results({
            @Result(column="customer_id", property="customerId", jdbcType=JdbcType.BIGINT),
            @Result(column="customer_name", property="customerName", jdbcType=JdbcType.VARCHAR),
            @Result(column="phone", property="phone", jdbcType=JdbcType.VARCHAR),
            @Result(column="email", property="email", jdbcType=JdbcType.VARCHAR),
            @Result(column="address", property="address", jdbcType=JdbcType.VARCHAR),
            @Result(column="gender", property="gender", jdbcType=JdbcType.INTEGER),
            @Result(column="remark", property="remark", jdbcType=JdbcType.VARCHAR),
            @Result(column="id_card", property="idCard", jdbcType=JdbcType.VARCHAR),
            @Result(column="user_id", property="userId", jdbcType=JdbcType.BIGINT),
            @Result(column="base_id", property="baseId", jdbcType=JdbcType.BIGINT),
            @Result(column="realname", property="realname", jdbcType=JdbcType.VARCHAR),
            @Result(column="section", property="section", jdbcType=JdbcType.VARCHAR)
    })
    Customer selectByPrimaryKey(Long customerId);

    @UpdateProvider(type=CustomerSqlProvider.class, method="updateByPrimaryKeySelective")
    int updateByPrimaryKeySelective(Customer record);
}